import java.util.Scanner;

public class Learn5 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int tmp = n % m;           //辗转相除法，求最大公约数
        while(tmp != 0){
            n = m;
            m = tmp;
            tmp = n % m;
        }
        System.out.println(m);
    }
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
                int n = scanner.nextInt();
                int m = scanner.nextInt();
                int i = n > m?m:n;
                for(;i > 0;i--){
                    if(n % i == 0&& m % i == 0){
                        System.out.println(i);
                        break;
                    }
                }
    }
}
